<!DOCTYPE html>
<html>
<head>
    <title>平台管理</title>
    <#include "/header.html">
    <link
            href="${request.contextPath}/statics/plugins/jquery-layout/jquery.layout-latest.css"
            rel="stylesheet" />
    <link
            href="${request.contextPath}/statics/css/bootstrapZtree.css"
            rel="stylesheet" />
</head>
<body>


<div id="rrapp" v-cloak class="container-div ui-layout-center">
    <div v-show="showList">
        <div class="grid-btn">
            <div class="form-group col-sm-2">
                <input type="text" class="form-control" v-model="q.platformName"
                       @keyup.enter="query" placeholder="平台名称">
            </div>
            <a class="btn btn-default" @click="query">查询</a>
            <a class="btn btn-primary" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</a>
            <a class="btn btn-primary" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</a>
            <a class="btn btn-danger" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
</div>


<div class="col-sm-12 select-info table-striped">
    <table id="bootstrap-table" data-mobile-responsive="true"></table>
</div>
</div>

<div v-show="!showList" class="panel panel-default"  >
    <div class="panel-heading">{{title}}</div>
    <form class="form-horizontal" id="form">
        <div class="form-group">
            <div class="col-sm-2 control-label">平台名称</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" v-model="user.platformName" placeholder="平台名称"/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">平台昵称</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" v-model="user.nickName" placeholder="平台昵称"/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">上线时间</div>
            <div class="col-sm-10">
                <input type="text" class="layui-input"  autocomplete="off" id="platCreatDate">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">选择数据源</div>
            <div class="col-sm-10">
                <select class="selectpicker" id="dataSource" data-live-search="true"></select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">选择站点</div>
            <div class="col-sm-10">
                <select class="selectpicker" id="siteSelect" multiple  data-live-search="true">

                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">第三方平台</div>
            <div class="col-sm-10">
                <select class="selectpicker" id="thirdOs" data-live-search="true">
                        <option value="">请选择第三方平台</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">新广告系统</div>
            <div class="col-sm-10">
                <select class="selectpicker" id="newAdSys" data-live-search="true">
                    <option value="">请选择新广告系统</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">第三方渠道</div>
            <div class="col-sm-10">
                <select class="selectpicker" id="thirdChannel" data-live-search="true">
                    <option value="">请选择第三方渠道</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">排序号</div>
            <div class="col-sm-10">
                <input type="number" class="form-control" v-model="user.sort" placeholder="排序号"/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label"></div>
            <input type="button" ref="submitBtn" class="btn btn-primary" @click="saveOrUpdate" value="确定"/>
            &nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="reload" value="返回"/>
        </div>
    </form>

</div>


</div>


<script
        src="${request.contextPath}/statics/plugins/jquery-layout/jquery.layout-latest.js"></script>
<script
        src="${request.contextPath}/statics/js/zTreeCore.js"></script>
<script
        src="${request.contextPath}/statics/js/zTreeEdit.js"></script>
<script
        src="${request.contextPath}/statics/js/zTreeExcheck.js"></script>

<!-- <script src="${request.contextPath}/statics/js/modules/sys/user.js?_${.now?long}"></script>
-->
<script>


    $(document)
        .ready(
            function() {
                $('body').layout({
                    west__size : 185
                });
                /* queryUserList();*/

                $("#siteSelect").selectpicker({
                    noneSelectedText: '请选择',
                    countSelectedText: function(){}
                });
                $("#dataSource").selectpicker({
                    noneSelectedText: '请选择',
                    countSelectedText: function(){}
                });
                $("#thirdOs").selectpicker({
                    noneSelectedText: '请选择',
                    countSelectedText: function(){}
                });
                $("#thirdChannel").selectpicker({
                    noneSelectedText: '请选择',
                    countSelectedText: function(){}
                });
                layui.use('laydate', function() {
                    var laydate = layui.laydate;
                     //日期范围
                    laydate.render({
                        elem: '#platCreatDate'
                        ,value:''
                    });
                });
                vm.changeSelect();
                 $('#bootstrap-table')
                    .bootstrapTable(
                        {
                            method : 'get', // 服务器数据的请求方式 get or post
                            url : baseURL + 'platform/findPlatformPage', // 服务器数据的加载地址
                            showRefresh : true,
                            showToggle : true,
                            showColumns : true,
                            //showExport :true,
                            sortable: true,
                            sortName:"userId",// 排序列名称
                            sortOrder: "desc",
                            iconSize : 'outline',
                            toolbar : '#exampleToolbar',
                            striped : true, // 设置为true会有隔行变色效果
                            dataType : "json", // 服务器返回的数据类型
                            pagination : true, // 设置为true会在底部显示分页条
                            // queryParamsType : "limit",
                            // //设置为limit则会发送符合RESTFull格式的参数
                            singleSelect : false, // 设置为true将禁止多选
                            // contentType : "application/x-www-form-urlencoded",
                            // //发送到服务器的数据编码类型
                            pageSize : 10, // 如果设置了分页，每页数据条数
                            pageNumber : 1, // 如果设置了分布，首页页码
                            // search : true, // 是否显示搜索框
                            //showColumns : false, // 是否显示内容下拉框（选择显示的列）
                            sidePagination : "server", // 设置在哪里进行分页，可选值为"client" 或者
                            // "server"
                            queryParams : function(params) {
                                //console.log(params)
                                return {
                                    // 说明：传入后台的参数包括offset开始索引，limit步长，sort排序列，order：desc或者,以及所有列的键值对
                                    limit : params.limit,
                                    page : (params.offset/params.limit) + 1,
                                    platformName : vm.q.platformName,
                                   // sidx: params.sort,      //排序列名
                                    //order: params.order //排位命令（desc，asc）
                                    /* sort:"userId",
                                    order:"desc" */
                                };
                            },
                            // //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果
                            // queryParamsType = 'limit' ,返回参数必须包含
                            // limit, offset, search, sort, order 否则, 需要包含:
                            // pageSize, pageNumber, searchText, sortName,
                            // sortOrder.
                            // 返回false将会终止请求
                            columns : [
                                {
                                    checkbox : true
                                },
                                {
                                    field : 'platformName',
                                    align:'center',
                                    title : '平台名称'
                                },
                                {
                                    field : 'nickName',
                                    align:'center',
                                    title : '平台昵称'
                                },
                                {
                                    field : 'username', // 列字段名
                                    align:'center',
                                    title : '用户名',// 列标题
                                },
                                {
                                    field : 'thirdpartPlatformName',
                                    align:'center',
                                    title : '第三方平台'
                                },
                                {
                                    field : 'thirdpartyChannelName',
                                    align:'center',
                                    title : '第三方渠道名称'
                                },
                               {
                                    field : 'newAdSystemPlatformName',
                                    align:'center',
                                    title : '第三方广告系统'
                                },
                                {
                                    field : 'sort',
                                    align:'center',
                                    title : '序号'
                                },
                                {
                                    field : 'createTime',
                                    title : '创建时间',
                                    align:'center',
                                    width:200,
                                    titleTooltip: "this is name"
                                },
                                {
                                    field : 'onlineTime',
                                    title : '上线时间',
                                    align:'center',
                                    width:200,
                                    titleTooltip: "this is name"
                                },
                                {
                                    title : '操作',
                                    field : 'id',
                                    width:330,
                                    align : 'center',
                                    formatter : function(
                                        value, row,
                                        index) {
                                        var e = '<a  class="btn btn-primary btn-sm '
                                            + ''
                                            + '" href="#" mce_href="#" title="编辑" onclick="edit(\''
                                            + row.platformId
                                            + '\')"><i class="fa fa-edit "></i>编辑</a> ';
                                        var c = '<a  class="btn btn-info btn-sm '
                                            + ''
                                            + '" href="#" mce_href="#" title="应用"  onclick="bindBaidu(\''
                                            + row.platformId
                                            + '\')"><i class="fa fa-hand-pointer-o" style="margin-right: 5px"></i>应用</a> ';
                                        var f = '<a  class="btn btn-success btn-sm '
                                            + ''
                                            + '" href="#" mce_href="#" title="媒体"  onclick="bindMeida(\''
                                            + row.platformId
                                            + '\')"><i class="fa fa-language" style="margin-right: 5px"></i>媒体</a> ';
                                        var d = '<a class="btn btn-danger btn-sm '
                                            + ''
                                            + '" href="#" title="删除"  mce_href="#" onclick="remove(\''
                                            + row.platformId
                                            + '\')"><i class="fa fa-remove" style="margin-right: 5px"></i>删除</a> ';
                                        return e + c + f + d;
                                     }
                                } ]
                        });
            });
    var setting = {
        data:{
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "accountId",
                rootPId: -1
            }
        },

        view: {
            // addHoverDom: addHoverDom,
            // removeHoverDom: removeHoverDom,
            selectedMulti: false
        },
        check: {
            enable: true,
            chkStyle : "checkbox",    //复选框
            chkboxType : {
                "Y" : "ps",
                "N" : "ps"
            }
        },
        callback : {
            beforeClick : beforeClick,
            onCheck : onCheck
        }
    };
    var ztree;
    function beforeClick(treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj("siteType");
        zTree.checkNode(treeNode, !treeNode.checked, null, true);
        return false;
    }
    function onCheck(e, treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj("siteType");
        var nodes = zTree.getCheckedNodes(true);
        //console.log(nodes)
        vm.checkNode = [];
        for (var i = 0, l = nodes.length; i < l; i++) {
            if (!nodes[i].isParent) {       //isParent判断是否为父级，也就是是否有下级
                vm.checkNode.push(nodes[i].id);    //获取所选节点的名称
            }
        }
        // console.log(vm.checkNode)
    };

    var vm = new Vue({
        el : '#rrapp',
        data : {
            q : {
                platformName : null
            },
            showList : true,
            platformId:null,
            title : null,
            roleList : {},
            allSite:[],
            user : {
                platformName:'',
                dataSourceId:'',
                newAdSystemPlatformId:'',
                thirdpartyPlatformId:'',
                thirdpartyChannelId:'',
                onlineTime:'',
                nickName:'',
                sort:''
            }
        },
        methods : {
            getMenu:function (id) {

                $.ajax({
                    type : "POST",
                    async:false,
                    url : baseURL + "biddingMedia/findBiddingMediaBind",
                    contentType : "application/json",
                    data : JSON.stringify({platformId:id}),
                    success : function(r) {
                        if (r.code == 0) {
                            var menuList = [];
                            menuList = r.result.childList.concat(r.result.parentList);
                            //console.log(menuList)
                            ztree = $.fn.zTree.init($("#siteType"), setting, menuList);
                            var arr = [];
                            var parentArr = [];
                            menuList.map(function (item) {
                                if(arr.indexOf(item.id) == -1){
                                    arr.push(item.id)
                                }
                            });
                            for(var j=0;j< r.result.bindChildList.length;j++){
                                for(var i=0;i<menuList.length;i++){
                                    if(( r.result.bindChildList[j]==menuList[i].id)&&(parentArr.indexOf(menuList[i].accountId)==-1)){
                                        parentArr.push(menuList[i].accountId);
                                    }

                                }
                            }
                            console.log(parentArr);
                            var bindList = [];
                            bindList =  r.result.bindChildList.concat(parentArr);
                            bindList.map(function (item) {
                                if(arr.indexOf(item)!= -1){
                                    ztree.checkNode(ztree.getNodeByParam("id", item), true, false);
                                }
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            },
            query : function() {
                vm.reload();
            },
            add : function() {
                vm.showList = false;
                vm.title = "新增";
                vm.roleList = {};
                vm.user = {
                    platformName:'',
                    dataSourceId:'',
                    newAdSystemPlatformId:'',
                    thirdpartyPlatformId:'',
                    thirdpartyChannelId:'',
                    nickName:'',
                    onlineTime:'',
                    sort:''
                };
                $("#platCreatDate").val("");
                vm.getDataSource();
                vm.getAllSite();
                vm.getThirdOs();
                vm.getThirdChannel();
                vm.getNewAdSys();
             },
           getNewAdSys:function(){
               $("#newAdSys").find(".addOption3").remove();
               $.ajax({
                   type : "GET",
                   async: false,
                   url : baseURL + "thirdpartyPlatform/findAllNewSystemThirdpartyPlatform",
                   data:{},
                   contentType : "application/json",
                   success : function(r) {
                       if (r.code === 0) {
                           var str = '';
                           r.result.map(function (item) {
                               str = str + '<option class="addOption3" value="'+ item.newAdSystemPlatformId +'">' + item.platformName + '</option>';
                           });
                           $("#newAdSys").append(str);
                           $('#newAdSys').selectpicker('refresh');
                       } else {
                           alert(r.msg);
                       }
                   }
               });
           },
           getThirdOs:function () {
               $("#thirdOs").find(".addOption3").remove();
               $.ajax({
                   type : "GET",
                   async: false,
                   url : baseURL + "thirdpartyPlatform/findAllThirdpartyPlatform",
                   data:{},
                   contentType : "application/json",
                   success : function(r) {
                       if (r.code === 0) {
                           var str = '';
                           r.result.map(function (item) {
                               str = str + '<option class="addOption3" value="'+ item.thirdpartyPlatformid +'">' + item.platformName + '</option>';
                           });
                           $("#thirdOs").append(str);
                           $('#thirdOs').selectpicker('refresh');
                       } else {
                           alert(r.msg);
                       }
                   }
               });
           },
           getThirdChannel:function () {
               $("#thirdChannel").find(".addOption3").remove();
               $.ajax({
                   type : "GET",
                   async: false,
                   url : baseURL + "platformChannel/findAllThirdpartyChannel",
                   data:{},
                   contentType : "application/json",
                   success : function(r) {
                       if (r.code === 0) {
                           var str = '';
                           r.result.map(function (item) {
                               str = str + '<option class="addOption3" value="'+ item.channelId +'">' + item.channelName + '</option>';
                           });
                           $("#thirdChannel").append(str);
                           $('#thirdChannel').selectpicker('refresh');
                       } else {
                           alert(r.msg);
                       }
                   }
               });
           },
           getAllSite:function (platformId) {
               platformId ? vm.platformId = platformId:vm.platformId = null;
               $("#siteSelect").find(".addOption").remove();
               $.ajax({
                   type : "POST",
                   url : baseURL + "ip/findBindSiteList",
                   contentType : "application/json",
                   data:JSON.stringify({platformId:vm.platformId}),
                   success : function(r) {
                       if (r.code === 0) {
                           vm.allSite = r.result;
                           var str = '';
                           for(var i=0;i<r.result.cateList.length;i++){
                               str = str + '<optgroup label="'+r.result.cateList[i].name+'">';
                               for(var j=0;j<r.result.cateList[i].siteList.length;j++){
                                   str = str + '<option class="addOption" value="'+ r.result.cateList[i].siteList[j].id +'">'
                                       + r.result.cateList[i].siteList[j].name + '</option>';
                               }
                               str = str + '</optgroup>'
                           }
                           //console.log(str)
                           $("#siteSelect").append(str);
                           $('#siteSelect').selectpicker('refresh');
                            if(r.result.bindList.length>0){
                               $('#siteSelect').selectpicker('val',r.result.bindList);
                               $('#siteSelect').selectpicker('refresh');
                           }
                           vm.displaySelect();
                         } else {
                           alert(r.msg);
                       }
                   }
               });
           },
            getDataSource:function () {
                $("#dataSource").find(".addOption2").remove();
                $.ajax({
                    type : "POST",
                    url : baseURL + "dataSource/findDataSourceList",
                    async: false,
                    data:{},
                    contentType : "application/json",
                    success : function(r) {
                        if (r.code === 0) {
                            var str = '';
                            r.result.map(function (item) {
                                str = str + '<option class="addOption2" value="'+ item.id +'">' + item.sourceName + '</option>';
                            });
                            $("#dataSource").append(str);
                            $('#dataSource').selectpicker('refresh');
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            },
           displaySelect:function () {
               var optgroup = $('#siteSelect optgroup');
               if($('#siteSelect').val()){
                   var siteSelectVal = $('#siteSelect').val();
                   for(var i=0;i<optgroup.length;i++){
                       here:
                           for(var k=0;k<optgroup.eq(i).find('option').length;k++){
                               for(var j=0;j<siteSelectVal.length;j++){
                                   if(optgroup.eq(i).find('option').eq(k).attr('value')==siteSelectVal[j]){
                                       optgroup.eq(i).find('option').eq(k).attr('disabled',false).siblings().attr('disabled','disabled')
                                       $('#siteSelect').selectpicker('refresh')
                                       break here;
                                   }else{
                                       optgroup.eq(i).find('option').attr('disabled',false)
                                       $('#siteSelect').selectpicker('refresh')
                                   }
                               }
                           }
                   }
               }else{
                   optgroup.find('option').attr('disabled',false)
                   $('#siteSelect').selectpicker('refresh')
               }
           },
           changeSelect:function () {
               $('#siteSelect').on('changed.bs.select',function(e){
                  // console.log($(this).val());
                     vm.displaySelect();
                     });
               $('#dataSource').on('changed.bs.select',function(e){
                   // console.log($(this).val());

               });
               $('#thirdOs').on('changed.bs.select',function(e){
                   // console.log($(this).val());

               });
           },
           update : function() {
              // console.log(11111)
               vm.user = {
                   platformName:'',
                   dataSourceId:'',
                   newAdSystemPlatformId:'',
                   thirdpartyPlatformId:'',
                   onlineTime:'',
                   nickName:'',
                   sort:''
               };
               $("#platCreatDate").val("");
                var userId = getSelectedRow();
                if (userId == null) {
                    return;
                }
               vm.getDataSource();
               vm.getThirdOs();
               vm.getThirdChannel();
               vm.getNewAdSys();
               vm.title = "修改";
               vm.getAllSite(userId.platformId);
               vm.getUser(userId.platformId);
             },
            del : function() {
                var userIds = getSelectedRow();
                if (userIds == null) {
                    return;
                }
                 confirm('确定要删除选中的记录？', function() {
                    $.ajax({
                        type : "POST",
                        url : baseURL + "platform/deletePlatform",
                        contentType : "application/json",
                        data : JSON.stringify({platformId:userIds.platformId}),
                        success : function(r) {
                            if (r.code == 0) {
                                alert('操作成功', function() {
                                    vm.reload();
                                });
                            } else {
                                alert(r.msg);
                            }
                        }
                    });
                });
            },
            saveOrUpdate : function() {
                var url = vm.user.platformId == null ? "platform/saveSysPlatform"
                    : "platform/updatePlatform";
                //console.log(vm.user.platformId);
                var btn = vm.$refs.submitBtn;
                vm.user.dataSourceId = $('#dataSource').val();
                if(checkIsBank(vm.user.platformName) || checkIsBank(vm.user.nickName) || checkIsBank($('#dataSource').val()) || checkIsBank(vm.user.sort)){
                  alert("全部为必填字段!");
                  return false;
                }
                vm.user.siteId = $('#siteSelect').val();
                vm.user.onlineTime =  $("#platCreatDate").val();
                vm.user.thirdpartyPlatformId = $('#thirdOs').val();
                vm.user.thirdpartyChannelId = $('#thirdChannel').val();
                vm.user.newAdSystemPlatformId =  $('#newAdSys').val();
                btn.disabled = true;
                $.ajax({
                    type : "POST",
                    url : baseURL + url,
                    contentType : "application/json",
                    data : JSON.stringify(vm.user),
                    success : function(r) {
                        btn.disabled = false;
                        if (r.code === 0) {
                            alert('操作成功', function() {
                                vm.reload();
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            },
            getUser : function(platformId) {
                $.ajax({
                    type : "POST",
                    url : baseURL + "platform/findPlatformById",
                    contentType : "application/json",
                    data : JSON.stringify({platformId:platformId}),
                    success : function(r) {
                        if (r.code === 0) {
                            vm.user.platformName = r.platform.platformName;
                            vm.user.platformId = r.platform.platformId;
                            vm.user.sort = r.platform.sort;
                            vm.user.nickName = r.platform.nickName;
                            vm.user.onlineTime = r.platform.onlineTime;
                            $("#platCreatDate").val(r.platform.onlineTime);
                            $('#dataSource').selectpicker('val',r.platform.dataSourceId);
                            $('#dataSource').selectpicker('refresh');
                            $('#thirdOs').selectpicker('val',r.platform.thirdpartyPlatformId);
                            $('#thirdOs').selectpicker('refresh');
                            $('#thirdChannel').selectpicker('val',r.platform.thirdpartyChannelId);
                            $('#thirdChannel').selectpicker('refresh');
                            $('#newAdSys').selectpicker('val',r.platform.newAdSystemPlatformId);
                            $('#newAdSys').selectpicker('refresh');
                            vm.showList = false;
                          } else {
                            alert(r.msg);
                        }
                    }
                });
            },
            reload : function() {
                vm.showList = true;
                // var opt = {
                //     url: baseURL + 'platform/findPlatformPage',
                //     silent: true,
                //     query:{
                //         limit : 10,
                //         page : 0,
                //         platformName : vm.q.platformName
                //     }
                // };
                $('#bootstrap-table').bootstrapTable('refresh',
                    {
                        platformName : vm.q.platformName
                    });

            }
        }
    });

 function edit(id) {
     if (id == null) {
         return;
     }
     //console.log(2222)
     vm.user = {
         platformName:'',
         dataSourceId:'',
         thirdpartyPlatformId:'',
         newAdSystemPlatformId:'',
         thirdpartyChannelId:'',
         onlineTime:'',
         nickName:'',
         sort:''
     };
     $("#platCreatDate").val("");
     vm.showList = false;
     vm.title = "修改";
     vm.getDataSource();
     vm.getThirdOs();
     vm.getNewAdSys();
     vm.getThirdChannel();
     vm.getAllSite(id);
     vm.getUser(id);
}

function remove(id) {
     confirm('确定要删除选中的记录？', function() {
        $.ajax({
            type : "POST",
            url : baseURL + "platform/deletePlatform",
            contentType : "application/json",
            data : JSON.stringify({platformId:id}),
            success : function(r) {
                if (r.code == 0) {
                    alert('操作成功', function() {
                        vm.reload();
                    });
                } else {
                    alert(r.msg);
                }
            }
        });
    });
 }
 function bindBaidu(platformId) {
     var platformId = platformId;
     layer.open({
         type: 1,
         skin: 'layui-layer-molv',
         title: "平台与百度移动应用绑定",
         area: ['550px', '450px'],
         shadeClose: false,
         content:modalCon(),
         btn: ['确定', '取消'],
         success:function (layero, index) {
             //console.log(index,'111111');
             getBaiduMobile();
             listenSelectChange(platformId);
         },
         btn1: function (index) {
            var params = {
                platformId:platformId,
                baiduMobileAppId:$("#platformSel").val()
            };
             $.ajax({
                 type: "POST",
                 url: baseURL + "platform/bindPlatformBaiduMobileApp",
                 contentType : "application/json",
                 data:JSON.stringify(params),
                 dataType: "json",
                 success: function (result) {
                     if (result.code == 0) {
                         layer.close(index);
                         alert('操作成功', function() {
                             vm.reload();
                         });
                     } else {
                         layer.alert(result.msg);
                     }
                 }
             });
         }
     });
 }
 function modalCon() {


     return  ' <div class="row" style="width:98%;margin: 20px auto">'
         +'<div class="col-sm-12">'
         +'<div class="input-group">'
         +'<span class="input-group-addon"> 百度账号:</span>'
         +'<select class="selectpicker" id="baiduSel" title="请选择百度移动账号"  style="width:100%;">' +
         '</select>'
         +'</div>'
         +'</div>'
         +'<div class="col-sm-12" style="margin-top: 20px">'
         +'<div class="input-group">'
         +'<span class="input-group-addon">应用名称:</span>'
         +'<select class="selectpicker" ' +
         'id="platformSel" ' +
         'data-actions-box="true" ' +
         'data-select-all-text="全选" ' +
         'data-deselect-all-text="取消全选" ' +
         'data-deselect-all-text="全选" ' +
         'title="请选择平台名称"' +
         ' multiple  style="width:100%;" >' +
         '</select>'
         +'</div>'
         +'</div>'
         +'</div>';
 }
function getBaiduMobile() {
    $.ajax({
        type : "post",
        url : baseURL+"baiduMobileAccount/findBaiduMobileSimpleAccount",
        dataType : "json",
        success: function(data) {
            if(data.code==0){
                var _html = '';
                for(var i=0;i<data.result.length;i++){
                    _html = _html + '<option value="'+data.result[i].id+'">'+data.result[i].username+'</option>'
                }
                $('#baiduSel').html(_html);
                //$('#baiduSel').val(activeSelect)
                $('#baiduSel').selectpicker('refresh');
         }else{
                layer.msg('数据获取失败');
            }
        },
        error:function(){
           layer.msg('数据获取失败');
        }
    });
}
function listenSelectChange(platformId) {
    getSelectedApp(platformId);
    $('#baiduSel').on('changed.bs.select',function(e){
        // console.log($(this).val());
        if($(this).val()){
            getBaiduMobileApp($(this).val());
        }
    });
}
function  getBaiduMobileApp(id) {
     $.ajax({
        type : "post",
        url : baseURL+"baiduMobileAppInfo/findBaiduMobileAppSimpleInfo",
        dataType : "json",
        contentType : "application/json",
        data:JSON.stringify({
            accountId:id
        }),
        success: function(data) {
            if(data.code==0){
                var _html = '';
                for(var i=0;i<data.result.length;i++){
                    _html = _html + '<option value="'+data.result[i].aid+'">'+data.result[i].appNameInfo+'</option>'
                }
                $('#platformSel').html(_html);
                $('#platformSel').selectpicker('refresh');
            }else{
                layer.msg('数据获取失败');
            }
        },
        error:function(){
            layer.msg('数据获取失败');
        }
    });
}
function getSelectedApp(id) {
     var selectedId = [];
     var allSelect = [];
     var accountId = '';
    $.ajax({
        type : "post",
        url : baseURL+"baiduMobileAppInfo/getPlatformBaiduMobileAppBindInfo",
        dataType : "json",
        contentType : "application/json",
        data:JSON.stringify({
            platformId:id
        }),
        success: function(data) {
              if(data.code==0){
                var _html = '';
                for(var i=0;i<data.result.length;i++){
                    for(var j=0;j<data.result[i].appInfo.length;j++){
                        if(data.result[i].appInfo[j].choose){
                            allSelect = data.result[i].appInfo;
                            selectedId.push(data.result[i].appInfo[j].aid);
                            accountId = data.result[i].mobileAccountId;
                        }
                    }
                 }
                 for(var k=0;k<allSelect.length;k++){
                     _html = _html + '<option value="'+ allSelect[k].aid +'">'+ allSelect[k].appNameInfo +'</option>';
                 }
                $('#platformSel').html(_html);
                $('#platformSel').val(selectedId);
                $('#platformSel').selectpicker('refresh');
                $('#baiduSel').val(accountId);
                $('#baiduSel').selectpicker('refresh');
            }else{
                layer.msg('数据获取失败');
            }
        },
        error:function(){
            layer.msg('数据获取失败');
        }
    });
};
 function bindMeida(id) {
     vm.getMenu(id);
     var platformId = id;
     layer.open({
         type: 1,
         offset: '50px',
         skin: 'layui-layer-molv',
         title: "选择站点",
         area: ['400px', '450px'],
         shadeClose: false,
         content: jQuery("#siteLayer"),
         btn: ['确定', '取消'],
         btn1: function (index) {
             onCheck();
             var params = {
                 platformId :platformId ,
                 mediaAccountId:vm.checkNode
             };
             //console.log(params);
             $.ajax({
                 type : "POST",
                 url : baseURL + "biddingMedia/bindBiddingMediaBind",
                 contentType : "application/json",
                 data : JSON.stringify(params),
                 success : function(r) {
                     if (r.code === 0) {
                         alert('操作成功', function() {
                             layer.close(index);
                             vm.reload();
                         });
                     } else {
                         alert(r.msg);
                     }
                 }
             });


         }
     });
 }
</script>

<!-- 选择菜单 -->
<div id="siteLayer" style="display: none;padding:10px;">
    <ul id="siteType" class="ztree"></ul>
</div>
</body>
</html>